package call_4;

import com.sun.org.apache.xpath.internal.operations.Bool;

import java.io.*;
import java.util.ArrayList;
import java.util.Random;

public class call {
    public static void main(String[] args) throws IOException {
        Random rand = new Random();
        ArrayList<Student> student = new ArrayList<>();
        BufferedReader br = new BufferedReader(new FileReader("namesboyandgils.txt"));
        String line;
        while ((line = br.readLine()) != null){
            String[] arr = line.split("-");
            Student s = new Student(arr[0], arr[1], Integer.parseInt(arr[2]), Boolean.parseBoolean(arr[3]));
            student.add(s);
        }
        br.close();
        int num = rand.nextInt(student.size());
        while (student.get(num).isTi()) {
            num = rand.nextInt(student.size());
            for (int i = 0; i < student.size(); i++) {
                if (!student.get(i).isTi()) {
                    break;
                }
                if (i == 9 && student.get(i).isTi()) {
                    System.out.println("点完一轮，开始下一轮");
                    for (Student s : student) {
                        s.setTi(false);
                    }
                }
            }
        }

        System.out.println(student.get(num).getName());
        student.get(num).setTi(true);

        BufferedWriter bw = new BufferedWriter(new FileWriter("namesboyandgils.txt"));
        for (Student s : student) {
            bw.write(s.toString());
            bw.newLine();
        }
        bw.close();
    }
}
